# coding=utf-8
import time

from ToolsConfig import *
from ItemTools import IsSameItem
from FastComp import *

CdTags = {}


class BlueFoxFilterEnum(object):
    """
    事件过滤器枚举值
    """

    class ServerEvent(object):
        class ProjectileDoHitEffectEvent(object):
            @staticmethod
            def IsEntityInList(entityStrType):
                # type:(List) -> Callable

                """
                是否为规定的生物
                """

                def _(args):
                    return serverCompFactory.CreateEngineType(args['id']).GetEngineTypeStr() in entityStrType

                return _

        class NormalEvent(object):
            @staticmethod
            def NotInCd(cdTag, cdSize):
                # type:(str,float) -> Callable
                """
                是否在CdTag所设置的Cd之外，注意cdTag是所有事件通用的
                """

                def _(*args):
                    lastTime = CdTags.get(MOD_NAME + cdTag, 0)
                    if time.time() - lastTime >= cdSize:
                        CdTags[MOD_NAME + cdTag] = time.time()
                        return True
                    return False

                return _

            @staticmethod
            def IsNight():
                """
                是否为黑夜
                """

                def _(*args):
                    _time = serverCompFactory.CreateTime(LevelId).GetTime()
                    _time %= 24000
                    return 12000 <= _time < 24000

                return _

            @staticmethod
            def IsDay():
                """
                是否为白天
                """

                def _(*args):
                    _time = serverCompFactory.CreateTime(LevelId).GetTime()
                    _time %= 24000
                    return 0 <= _time < 12000

                return _

        class DestroyBlockEvent(object):
            @staticmethod
            def BlockNameInList(blockNameList):
                # type:(List[str]) -> Callable
                """
                被破坏的方块是否在规定的方块列表内
                """

                def _(args):
                    return args['fullName'] in blockNameList

                return _

        class ServerPlayerTryDestroyBlockEvent(object):
            @staticmethod
            def BlockNameInList(blockNameList):
                # type:(List[str]) -> Callable
                """
                被破坏的方块是否在规定的方块列表内
                """

                def _(args):
                    return args['fullName'] in blockNameList

                return _

            @staticmethod
            def NotCancel():
                """
                事件未被取消
                """

                def _(args):
                    return not args['cancel']

                return _

        class ServerBlockUseEvent(object):

            @staticmethod
            def BlockNameInList(blockNameList):
                # type:(List[str]) -> Callable
                """
                被使用方块是否在规定的方块列表内
                """

                def _(args):
                    return args['blockName'] in blockNameList

                return _

            @staticmethod
            def NoCarriedItem():
                """
                当没有手持物品时
                """

                def _(args):
                    return not bool(serverCompFactory.CreateItem(args['playerId']).GetPlayerItem(2, 0))

                return _

            @staticmethod
            def CarriedItem():
                """
                当有手持物品时
                """

                def _(args):
                    return bool(serverCompFactory.CreateItem(args['playerId']).GetPlayerItem(2, 0))

                return _

        class ItemUseOnAfterServerEvent(object):

            @staticmethod
            def NotInCd(cdTag, cdSize):
                # type:(str,float) -> Callable
                """
                是否在CdTag所设置的Cd之外
                """

                def _(args):
                    lastTime = CdTags.get(MOD_NAME + cdTag, 0)
                    if time.time() - lastTime >= cdSize:
                        CdTags[MOD_NAME + cdTag] = time.time()
                        return True
                    return False

                return _

            @staticmethod
            def IsBlock(blockName):
                # type:(str) -> Callable
                """
                是否是规定的被使用方块
                """

                def _(args):
                    return args['blockName'] == blockName

                return _

            @staticmethod
            def BlockNameInList(blockNameList):
                # type:(List[str]) -> Callable
                """
                被使用方块是否在规定的方块列表内
                """

                def _(args):
                    return args['blockName'] in blockNameList

                return _

            @staticmethod
            def IsItemDict(itemDict):
                # type:(Dict[str]) -> Callable
                """
                被使用的物品是否为规定的物品
                """

                def _(args):
                    return IsSameItem(args['itemDict'], itemDict)

                return _

            @staticmethod
            def ItemNameInList(itemNameList):
                # type:(List[str]) -> Callable
                """
                被使用的物品是否在规定的物品列表内
                """

                def _(args):
                    return args['itemDict']['itemName'] in itemNameList

                return _

        class DamageEvent(object):
            @staticmethod
            def DamageFilter(damage=0):
                """
                伤害数值过滤器, 当伤害大于等于输入的伤害时将会触发
                """

                def _(args):
                    return args['damage_f'] >= damage

                return _

            @staticmethod
            def CauseInList(causeList):
                # type:(List[str]) -> Callable
                """
                伤害类型过滤器, 当于输入的类型相同时触发
                """

                def _(args):
                    return args['cause'] in causeList

                return _

            @staticmethod
            def IgniteFilter():
                """
                忽视过滤器, 未被忽视时触发
                """

                def _(args):
                    return not args['ignite']

                return _

        @staticmethod
        def AttackerIsPlayer():
            """
            攻击者是否为玩家
            """

            def _(args):
                return IsPlayer(args['srcId'])

            return _

        @staticmethod
        def InjuredIsPlayer():
            """
            受伤者者是否为玩家
            """

            def _(args):
                return IsPlayer(args['entityId'])

            return _

        class ServerBlockEntityTickEvent(object):
            @staticmethod
            def BlockNameInList(blockNameList):
                """
                方块名称过滤器
                """

                def _(args):
                    return args['blockName'] in blockNameList

                return _

    class ClientEvent(object):
        pass
